'use strict'

module.exports = async (c,next) => {

    let token = c.headers.authorization || c.query.token

    if(!token){
        return c.status(403).send('TOKEN NULL')
    }

    let r = c.service.tok.verify(token)

    //通过ok判断是否成功失败，errcode属性表示失败的状态码
    if(!r.ok){
        //errcode的值可能是FAILED TIMEOUT ILLEGAL
        return c.status(403).send(r.errcode)
    }

    c.box.user = r.data

    await next()
}

